@extends('layouts.public')

@section('head')
    <link rel="stylesheet" href="{{cdn('js/plugins/webuploader/single.css')}}">
    <style>
        p {
            font-size: 12px;
            color:#ccc;
        }
    </style>
@endsection

@section('bodyattr')class="gray-bg"@endsection

@section('body')
    <div class="wrapper wrapper-content">
        <div class="row m-b">
            <div class="col-sm-12">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                    <li class="active"><a href="{{route('admin.share.shares')}}">分享列表</a></li>
                        <li @if(!isset($user))class="active"@endif><a href="{{route('admin.share.shares.add')}}">新增</a>
                        </li>
                        @if(isset($user))
                            <li class="active"><a href="#">编辑</a></li>
                        @endif
                    </ul>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form action="{{route('admin.share.shares.save')}}" method="post"
                              class="form-horizontal ajaxForm">
                            <input type="hidden" name="id" value="{{$user->id or 0}}"/>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">分享标题</label>
                                <div class="col-sm-5">
                                    <input type="text" class="form-control" name="title" require  maxlength="20"
                                           @if(isset($user)) value="{{$user->title or ''}}" placeholder="请填写分享标题"
                                           @endif autocomplete="off"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">分享标题</label>
                                <div class="col-sm-5">
                                    <input type="text" class="form-control" name="desc" require  maxlength="20"
                                           @if(isset($user)) value="{{$user->title or ''}}" placeholder="请填写分享描述"
                                           @endif autocomplete="off"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">分享主图</label>
                                <div class="col-sm-10" id="share_box">
                                    <div id="share_picker">选择图片</div>
                                    <p>图片用来展示小程序店铺主页，建议尺寸为110px*110px,效果更好</p>
                                    @if(isset($user) && $user->img != '')
                                        <div class="img-div">
                                            <img src="{{get_file_url($user->img)}}"/>
                                            <span class="cancel">×</span>
                                        </div>
                                    @endif
                                    <input type="hidden" id="share" name="img" value="{{$user->img or ''}}" require />
                                    <input type="hidden" id="share_file_id" name="share_file_id" value="" require/>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit">保存</button>
                                    <button class="btn btn-white" type="button" id="backBtn">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('script')
    <script src="{{cdn('js/plugins/webuploader/webuploader.nolog.min.js')}}"></script>
    <script src="{{cdn('js/plugins/webuploader/webuploader_public.js')}}"></script>
    <script type="text/javascript">
        jQuery(function ($) {
            singleUpload({
                _token: '{{csrf_token()}}',
                type_key: 'FT_ONE_RESOURCE',
                item_id: '{{$user->id or 0}}',
                pick: 'share_picker',
                boxid: 'share_box',
                file_path: 'share',
                file_id: 'share_file_id'
            });
            $('#share_box').find('.img-div>span').click(function () {
                sUploadDel($(this), 'share');
            });
            
        });
    </script>
@endsection